package com.lej.dataservice.club.room

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.lej.core.base.app
import com.lej.dataservice.club.bean.commercial.CommercialBean
import com.lej.dataservice.club.bean.commercial.PicBeanTypeConverters


@Database(entities = [CommercialBean::class], version = 8,exportSchema = false)
@TypeConverters(PicBeanTypeConverters::class)
abstract class AppDatabase : RoomDatabase() {
    abstract fun commercialDao(): CommercialDao

}

val MIGRATION_1_2 = object : Migration(1, 2) {
    override fun migrate(database: SupportSQLiteDatabase) {
        database.execSQL(
            "ALTER TABLE commercialbean "
                    + " ADD COLUMN showTime INTEGER"
        );
    }
}
val db: AppDatabase by lazy {
    Room.databaseBuilder(
        app,
        AppDatabase::class.java, "peng_db"
    )
        .addMigrations(MIGRATION_1_2)
        .fallbackToDestructiveMigration().build()
}